package com.guomao.entity;

import java.util.Objects;

public class Student extends Object implements Comparable<Student> {

    private String name;
    private int age;

    public int getAge() {
        return age;
    }

    public String getName() {
        return name;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public Student() {
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return age == student.age && Objects.equals(name, student.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }

    //this属性-形参属性
    @Override
    public int compareTo(Student o) {
//        int x = this.age - o.getAge();
//        x = x != 0 ? x : this.name.compareTo(o.name);
//        return x;

        int x = o.age - this.getAge();
        x = x != 0 ? x : o.getName().compareTo(this.getName());
        return x;
    }
}
